<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>

        function newObj(name, age) {
            let obj = new Object()
            obj.name = name;
            obj.age = age;
            return obj
        }

        obj1 = newObj("张三", 12)
        console.log(obj1)


        function newObj2(name, age) {
            this.name = name;
            this.age = age;
            this.class = "ClassOne";
        }

        obj2 = new newObj2("李四", 13)
        console.log(obj2)


        function newObj3(name, age) {
            this.name = name;
            this.age = age;
            this.abc = function() {
                console.log("abc")
            }
        }

        obj3 = new newObj3("王五", 13)
        console.log(obj3)
        obj3.abc()


        // 1.创建一个 Car 构造函数，接收 brand 和 year 参数，并添加一个 displayInfo 方法，打印车辆信息。
        // 升级：通过原型添加一个 getAge 方法

        function Car(brand, year) {
            this.brand = brand
            this.year = year
            this.displayInfo = () => {
                console.log(brand, year)
            }
        }

        Car.prototype.getAge = function () {
            let year = new Date().getFullYear() - this.year
            console.log(year)
        }

        car1 = new Car("A", 2015)
        car1.displayInfo()
        car1.getAge()
        console.log(car1)
        // console.log(car1.constructor)
    </script>
</body>
</html>